-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: define blog slug in frontmatter #48
base: master
Are you sure you want to change the base?
Conversation
Modify gatsby-node.js that reads in frontmatter slug and uses it for blog URL. If frontmatter is not defined or slug is not defined it will default to file path for slug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea! Just a little style modification and I accept this PR 😉
Thanks you 😃
gatsby-node.js
Outdated
@@ -36,9 +36,10 @@ exports.onCreateNode = ({node, boundActionCreators, getNode}) => { | |||
let slug; | |||
switch (node.internal.type) { | |||
case `MarkdownRemark`: | |||
const fmSlug = (node.frontmatter && node.frontmatter.slug) ? node.frontmatter.slug : false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you can use get
from lodash (https://lodash.com/docs/4.17.5#get), and I prefer long variable name instead of acronyms 😉
const frontmatterSlug = get(node, 'frontmatter.slug');
@jkornblum carefull you miss a semi-column ^^
You can run |
Thanks for feedback. I tried the one liner without the checks! I was burned 😄 Anyways I updated and cleaned up code, added unit test, and changed one markdown file use the frontmatter slug. Let me know if it looks okay. |
It looks good, I just need to check why netlify don't want to deploy ^^
Strange… I look this after, really thank you for your PR 👍 |
Modify
gatsby-node.js
so that it reads in frontmatter slug and uses it for blog URL. If frontmatter is not defined or slug is not defined it will default to file path for slug (current behavior).E.g. on the demo the first blog post is
demo.com/blog/2017-04-18--welcoming/
by addingslug
to front matter likethe new url would be
demo.com/blog/2017-04-18/my-article